package com.etrans.baf.analyse.task.alarm.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
 


import org.springframework.web.bind.annotation.RequestMapping;

import com.etrans.baf.analyse.task.alarm.service.AlarmService;
import com.etrans.baf.analyse.util.CommonUtil;
import com.etrans.baf.analyse.util.DateUtils;


@Component("alarmAnalyse")
@Controller
@RequestMapping("/task/alarm/alarmanalyse/*")
public class AlarmAnalyse {

	@Autowired
	private AlarmService alarmService;
	
	static final Logger logger = LoggerFactory.getLogger(AlarmAnalyse.class);

	public void timer(){
		logger.info("实时报警、 处警分析开始----------------");
		try {
			alarmService.alarmSwap();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logger.info("实时报警、 处警分析结束----------------");
		 
	}
	
	public void driverTimer(){
		logger.info("司机报警分析开始----------------");
		try {
			String analyse_date = DateUtils.getAnalyseDate(null,0);
			alarmService.driverAlarmSwap(analyse_date);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("司机报警分析异常---------");
		}
 		 
	}
	public void hotTimer(){
		logger.info("热区报警分析开始---------");
		try {
			String analyse_date = DateUtils.getAnalyseDate(null,0);
			alarmService.hotAlarmSwap(analyse_date);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("热区报警分析异常---------");
		}
	}
	@RequestMapping(value = "reDriverTimer.html")
	public void reDriverTimer(HttpServletRequest request,HttpServletResponse response){
		Map<String,String> map = new HashMap<String,String>();
		try {	
			logger.info("重分析司机报警分析----------------分析日期:"+request.getParameter("date"));
			String dateStr = (request.getParameter("date")!=null&& !"".equals(String.valueOf(request.getParameter("date"))))?String.valueOf(request.getParameter("date")):null;
			String analyse_date = DateUtils.getAnalyseDate(dateStr,0);
			alarmService.driverAlarmSwap(analyse_date);
			map.put("status", "ok");
		} catch (Exception e) {
			e.printStackTrace();
			map.put("status", "error:"+e.getMessage());
		}
		CommonUtil.ajaxResultJson(response, map);
	}
	@RequestMapping(value = "reHotTimer.html")
	public void reHotTimer(HttpServletRequest request,HttpServletResponse response){
		Map<String,String> map = new HashMap<String,String>();
		try {	
			logger.info("重分析热区报警分析----------------分析日期:"+request.getParameter("date"));
			String dateStr = (request.getParameter("date")!=null&& !"".equals(String.valueOf(request.getParameter("date"))))?String.valueOf(request.getParameter("date")):null;
			String analyse_date = DateUtils.getAnalyseDate(dateStr,0);
			alarmService.hotAlarmSwap(analyse_date);
			map.put("status", "ok");
		} catch (Exception e) {
			e.printStackTrace();
			map.put("status", "error:"+e.getMessage());
		}
		CommonUtil.ajaxResultJson(response, map);
	}
}
